﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum E_FireType
{
    //单发
    One,
    //双发
    Two,
    //扇形
    Three,
    //环形
    Round,
}

public class Lesson12_code1 : MonoBehaviour
{
    // Start is called before the first frame update
    public E_FireType fireType;
    private GameObject bullet;
    void Start()
    {
        bullet = Resources.Load<GameObject>("Prefab/Bullet");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            fireType = E_FireType.One;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            fireType = E_FireType.Two;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            fireType = E_FireType.Three;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            fireType = E_FireType.Round;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Fire();
        }
    }

    private void Fire()
    {
        switch (fireType)
        {
            case E_FireType.One:
                Instantiate(bullet, this.transform.position, this.transform.rotation);
                break;
            case E_FireType.Two:
                Instantiate(bullet, this.transform.position - this.transform.right * 0.5f, this.transform.rotation);
                Instantiate(bullet, this.transform.position + this.transform.right * 0.5f, this.transform.rotation);
                break;
            case E_FireType.Three:
                //面朝向
                Instantiate(bullet, this.transform.position, this.transform.rotation);
                //向左旋转20度-知识点:四元数*四元数=一个新的四元数,相当于旋转量的叠加
                Instantiate(bullet, this.transform.position, this.transform.rotation * Quaternion.AngleAxis(-20, Vector3.up));
                ////向左旋转20度
                Instantiate(bullet, this.transform.position, this.transform.rotation * Quaternion.AngleAxis(20, Vector3.up));
                break;
            case E_FireType.Round:
                for (int i=0; i<=8; i++)
                {
                    Instantiate(bullet, this.transform.position, this.transform.rotation * Quaternion.AngleAxis(i * 40, Vector3.up));
                }
                break;
        }
    }
}
